//1。双向链表
class Node{
    constructor(element){
        this.element=element
        this.next = null
        this.prve = null
    }
}
class Dobal{
    constructor(){
        this.head=null
        this.count=0
        this.tail = null
    }
    getElementAt(index){
        if(index>=0&&index<this.count){
            let current = this.head;
            for(let i = 0;i<index;i++){
                current  = current.next
            }
            return current 
        }
        return undefined
    }
    insert(element,index){
    if(index>=0&&index<=this.count){
        let node = new Node(element);
        let current = this.head;
        if(index===0){
            if(this.head===null){
                this.head = node
                this.tail = node
            }else{
                node.next = this.head
                current.prev = node
                this.head = node
            }
        }else if(index===this.count){
            current = this.tail
            current.next = node
            node.prev = current
            this.tail = node
        }else{
            let previous = this.getElementAt(index-1) 
            current = previous.next
            node.next = current
            previous.next = node
            current.prev = node
            node.prev = previous
        }
        this.count++
        return true
    }
    return false
}
removeAt(index){
    if(index>=0&&index<this.count){
        let current = this.head
        if(index===0){
            this.head = current.next
            if(this.count===1){
                this.tail = null
            }else{
                this.head.prev = null
            }
        }else if(index===this.count-1){
            current = this.tail
            this.tail = current.prev
            this.tail.next = null
        }else{
            current = this.getElementAt(index)
            const previous = current.prev
            previous.next = current.next
            current.next.prev = previous
        }
        this.count--
        return current
    }
    return false
}
}
// 2.栈
class Stack{
    constructor(){
        this.item={}
        this.count =0
    }
    push(element){//顶端添加
        this.item[this.count]=element
        this.count++
    }
    isEmpty(){//是否有元素
        return this.count ===0
    }
    clear(){//清空
        this.count=0
        this.item={}
    }
    pop(){//移出顶部
        if(this.isEmpty()){
            return undefined
        }
        this.count--
        const result = this.item[this.count]
        delete this.item[this.count]
        return result
    }
    peek(){//直接移出，不要返回值
        if(this.isEmpty()){
            return undefined
        }
        this.count--
        delete this.item[this.count]
    }
}
// 3.进制转换
function doc(num,num2){
    let remStack = new Stack()
    let rem ;//余数
    let remString='';
    while(num>0){
        rem = num%num2
        remStack.push(rem)
        num=Math.floor(num/num2)
    }
    while(!remStack.isEmpty()){
        remStack+=remStack.pop().toString()
    }
    return remString
}